<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<form class="layui-form"  lay-filter="outport-filter">
<div class="layui-form layuimini-form" lay-filter="editForm">
    <input type="hidden" name="id">
    <div class="layui-form-item">
        <label class="layui-form-label required">代理商名称</label>
        <div class="layui-input-block">
           <!-- <input type="text" name="agentName"  lay-verify="required" lay-reqtext="代理商名称不能为空" placeholder="请输入代理商名称"
                   value="" class="layui-input">-->
            <select name="agentName" lay-filter="agentName"  id="agent" lay-verify="required">
                <option value=""></option>
                <%--下拉选的动态渲染--%>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">商品名称</label>
        <div class="layui-input-block">
            <input type="text" name="goodsName"  lay-verify="required" lay-reqtext="商品名称不能为空" placeholder="请输入商品名称"
                   value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">支付类型</label>
        <div class="layui-input-block">
            <!--<input type="text" name="payType" lay-verify="required" lay-reqtext="支付类型不能为空" placeholder="请输入支付类型" value=""
                   class="layui-input">-->
            <select  name="payType"  lay-reqtext="支付类型不能为空" >
                <option>---请输入支付类型---</option>
                <option>微信</option>
                <option>支付宝</option>
                <option>银行卡</option>
                <option>现金</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">操作员</label>
        <div class="layui-input-block">
            <input type="text" name="operate" lay-verify="required" lay-reqtext="操作员不能为空" placeholder="请输入操作员" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">出库数量</label>
        <div class="layui-input-block">
            <input type="text" name="number" lay-verify="required" lay-reqtext="出库数量不能为空" placeholder="请输入出库数量" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">规格（箱、灌、瓶等）</label>
        <div class="layui-input-block">
            <input type="text" name="specs" lay-verify="required" lay-reqtext="规格不能为空" placeholder="请输入规格" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">出库价格</label>
        <div class="layui-input-block">
            <input type="text" name="price" lay-verify="required" lay-reqtext="出库价格不能为空" placeholder="请输入出库价格" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">出库时间</label>
        <div class="layui-input-block">
            <input type="date" name="saleTime" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="editBtn">确认保存</button>
        </div>
    </div>
</div>
</form>
<script src="/static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'],function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        // 根据出库信息的id  查询当前出库信息   数据回显
        var id = sessionStorage.getItem("id");
        $.get("/outport/getById", {id}, function (result) {
            //2.查询代理商列表  渲染代理商下拉选
            $.get('/agent/selectList', function (res) {
                //  res  供应商列表   [{},{}]
                // 获取select节点对象
                let select = $('#agent')
                res.forEach(agent => {
                    // 创建节点对象  option   <option value=1>管理员</option>
                    let option = $('<option>' + agent.agentName + '</option>').attr('value', agent.agentName)
                    select.append(option);
                })
                //  res  {username:'',sex:''}
                form.val('outport-filter',result)
                //重新渲染 form表单
                form.render();
            }, 'JSON')
           /* form.val('outport-filter',result)
            //重新渲染 form表单
            form.render();*/
        }, 'JSON')

        //监听提交
        form.on('submit(editBtn)', function (data) {
            let outportJSON = JSON.stringify(data.field)
            $.ajax({
                url: '/outport/edit',
                data: outportJSON,
                dataType: 'json',
                type: 'post',
                contentType: 'application/json;charset=utf-8',
                success: function (res) {
                    if (res.code == 0) {
                        layer.msg(res.msg, {icon: 1}, function () {
                            // 关闭弹出层
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                            // 重载表格
                            parent.layui.table.reload('currentTableId');
                        })
                    } else {
                        layer.msg(res.msg, {icon: 2})
                    }
                }
            })

            return false;
        });

    });
</script>
</body>
</html>